home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blitzblank / sources / bb.random < prev    next >
Text File  |  1993-09-17  |  4KB  |  210 lines

  1. ;BB.Random - Blanker-module for BlitzBlank
  2. ;Copyright 1993 by Thomas Boerkel
  3.  
  4. CloseEd
  5. NoCli
  6.  
  7. XINCLUDE dosasl.bb2
  8.  
  9. DEFTYPE.Screen *myscreen
  10. DEFTYPE.Message *msg,msg2
  11. DEFTYPE.MsgPort *port,*port2
  12. DEFTYPE.AnchorPath *ap
  13. DEFTYPE.l
  14.  
  15. Dim modname$(100)
  16. Dim modselect$(100)
  17.  
  18. Select Par$(1)
  19.   Case "BLANK"
  20.     Gosub readconfig
  21.     name$="BB.BlankModule"+Chr$(0)
  22.     If selected
  23.       Repeat
  24.         m=Rnd(selected)+1
  25.       Until selected=1 OR m<>last
  26.       last=m
  27.       Gosub writeconfig
  28.       dos$="run "+path$+"BB."+modselect$(m)
  29.  
  30.       For i=1 To 8
  31.         dos$+" "+Par$(i)
  32.       Next i
  33.       dos$+" "+path$+Chr$(0)
  34.       Execute_ &dos$,0,0
  35.       Repeat
  36.         Delay_ 5
  37.         Forbid_
  38.         *port2=FindPort_(&name$)
  39.         Permit_
  40.         cp+1
  41.       Until cp=40 OR *port2
  42.       If *port2
  43.         *port=CreateMsgPort_()
  44.         *port\mp_Node\ln_Name=&name$
  45.         *port\mp_Node\ln_Pri=2
  46.         AddPort_ *port
  47.       EndIf
  48.     EndIf
  49.     If *port2
  50.       Repeat
  51.         WaitPort_ *port
  52.         *msg=GetMsg_(*port)
  53.       Until *msg
  54.       RemPort_ *port
  55.       DeleteMsgPort_ *port
  56.     EndIf
  57.     Delay_ 10
  58.     Forbid_
  59.     *port=FindPort_(&name$)
  60.     Permit_
  61.     If *port
  62.       msg2\mn_Length=SizeOf.Message
  63.       PutMsg_ *port,msg2
  64.     EndIf
  65.     Delay_ 250
  66.   Case "INFO"
  67.     title$="Random"+Chr$(0)
  68.     reqtext$="Random - Module for BlitzBlank"+Chr$(10)
  69.     reqtext$+Chr$(169)+" 1993 by Thomas Brkel"+Chr$(10)+Chr$(10)
  70.     reqtext$+"Other modules will be randomly started."+Chr$(10)+Chr$(10)
  71.     reqtext$+"Choose which modules to start in the config-window."+Chr$(0)
  72.     gadget$="OK"+Chr$(0)
  73.     easy.EasyStruct\es_StructSize=SizeOf.EasyStruct
  74.     easy\es_Title=&title$
  75.     easy\es_TextFormat=&reqtext$
  76.     easy\es_GadgetFormat=&gadget$
  77.     EasyRequestArgs_ 0,easy,0,0
  78.   Case "CONFIG"
  79.  
  80.     *myscreen=LockPubScreen_(0)
  81.     width=*myscreen\Width
  82.     height=*myscreen\Height
  83.     font=*myscreen\Font\ta_YSize
  84.     Gosub readconfig
  85.     Gosub findmodules
  86.     WbToScreen 0
  87.     BorderPens 2,1
  88.     sp=Int(modules/10)
  89.     For x=0 To sp
  90.       For y=1 To 10
  91.         If x*10+y<=modules
  92.           TextGadget 0,x*140+20,y*13+10,1,x*10+y,LSet$(modname$(x*10+y),15)
  93.           For j=1 To selected
  94.             If modname$(x*10+y)=modselect$(j)
  95.               Toggle 0,x*10+y,On
  96.             EndIf
  97.           Next j
  98.         EndIf
  99.       Next y
  100.     Next x
  101.     ww=sp*140+170
  102.     Window 0,width/2-ww/2,height/2-80,ww,160,$100e,"Random",1,2,0
  103.     Repeat
  104.       ev=WaitEvent
  105.     Until ev=$200
  106.     selected=0
  107.     For i=1 To modules
  108.       If GadgetStatus(0,i)
  109.         selected+1
  110.         modselect$(selected)=modname$(i)
  111.       EndIf
  112.     Next i
  113.     Free Window 0
  114.     Gosub writeconfig
  115.     UnlockPubScreen_ 0,*myscreen
  116. End Select
  117.  
  118. End
  119.  
  120. .readconfig
  121. path$=Par$(9)
  122. For i=10 To NumPars
  123.   path$=path$+" "+Par$(i)
  124. Next i
  125. If ReadFile(0,path$+"BB.Modules.config")
  126.   FileInput 0
  127.   While NOT Eof(0)
  128.     If Edit$(100)="*** Random ***"
  129.       selected=Val(Edit$(5))
  130.       last=Val(Edit$(5))
  131.       For i=1 To selected
  132.         modselect$(i)=Edit$(30)
  133.       Next i
  134.     EndIf
  135.   Wend
  136.   DefaultInput
  137.   CloseFile 0
  138. EndIf
  139. Return
  140.  
  141.  
  142. .writeconfig
  143. If ReadFile(0,path$+"BB.Modules.config")
  144.   If WriteFile(1,path$+"BB.Modules.temp")
  145.     FileInput 0
  146.     FileOutput 1
  147.     While NOT Eof(0)
  148.       f$=Edit$(100)
  149.       If f$="*** Random ***"
  150.         Repeat
  151.           f2$=Edit$(100)
  152.         Until Eof(0) OR Left$(f2$,3)="***"
  153.         If NOT Eof(0) Then NPrint f2$
  154.       Else
  155.         NPrint f$
  156.       EndIf
  157.     Wend
  158.     CloseFile 1
  159.   EndIf
  160.   CloseFile 0
  161. EndIf
  162. KillFile path$+"BB.Modules.config"
  163. f$=path$+"BB.Modules.temp"+Chr$(0)
  164. f2$=path$+"BB.Modules.config"+Chr$(0)
  165. Rename_ &f$,&f2$
  166. If OpenFile(0,path$+"BB.Modules.config")
  167.   FileOutput 0
  168.   FileSeek 0,Lof(0)
  169.   NPrint "*** Random ***"
  170.   NPrint selected
  171.   NPrint last
  172.   For i=1 To selected
  173.     NPrint modselect$(i)
  174.   Next i
  175.   CloseFile 0
  176. EndIf
  177. Return
  178.  
  179. .findmodules
  180. modules=0
  181. modpattern$="BB."+Chr$(126)+"((#(#?.#?))|Random)"+Chr$(0)
  182. *ap=AllocMem_(SizeOf.AnchorPath,#MEMF_CLEAR)
  183. d$=path$+Chr$(0)
  184. l=Lock_(&d$,-2)
  185. old=CurrentDir_(l)
  186. If MatchFirst_(&modpattern$,*ap)=0
  187.   If *ap\ap_Info\fib_DirEntryType<0
  188.     modules+1
  189.     modname$(modules)=UnRight$(Peek$(*ap\ap_Info+8),3)
  190.   EndIf
  191.   While MatchNext_(*ap)=0
  192.     If *ap\ap_Info\fib_DirEntryType<0
  193.       modules+1
  194.       modname$(modules)=UnRight$(Peek$(*ap\ap_Info+8),3)
  195.     EndIf
  196.   Wend
  197. EndIf
  198. MatchEnd_ *ap
  199. FreeMem_ *ap,SizeOf.AnchorPath
  200. CurrentDir_ old
  201. UnLock_ l
  202. modname$(0)=Chr$(0)
  203. For i=modules+1 To 100
  204.   modname$(i)=Chr$(255)
  205. Next i
  206. Sort modname$()
  207. modname$(0)=""
  208.  
  209. Return
  210.